package controller;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Model;
import databean.Email;


import model.EmailDAO;

public class NotesAddAction extends Action {
	private EmailDAO emailDAO;
	
	public NotesAddAction(Model model) {
		this.emailDAO = model.getEmailDAO();
	}

	public String getName() { return "conversation-add-notes.do"; }
    
	
    public String perform(HttpServletRequest request,HttpServletResponse response) {
    	
    	List<String> errors = new ArrayList<String>();
    	
    	String messageId = request.getParameter("messageId");
    	String noteString = request.getParameter("noteString");
    	
    	long l = Long.parseLong(messageId);

    	
    	try {
			Email emailToUpdate = emailDAO.getEmail(l);
			emailToUpdate.setNotes(noteString);
			emailDAO.updateEmail(emailToUpdate);
			System.out.println("Update Successful");
    	} catch (SQLException e) {
			// TODO Auto-generated catch block        	
			e.printStackTrace();
			errors.add(e.getMessage());
	    	return "conversation-add-notes.jsp";
		}
    	

    	return "conversation-add-notes.jsp";
    }
    
    
}
